/**
 * com.cnhis.his.customer.service.Vae1Service.java
 */
package com.mbmed.doctor.login.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mbmed.doctor.commons.mapper.ModelVo;
import com.mbmed.doctor.homepage.bo.Rab1Bo;
import com.mbmed.doctor.homepage.bo.Rac1Bo;
import com.mbmed.doctor.homepage.bo.Rad1Bo;
import com.mbmed.doctor.homepage.bo.Vaj2Bo;
import com.mbmed.doctor.homepage.bo.Vam1Bo;
import com.mbmed.doctor.homepage.bo.Vao2Bo;
import com.mbmed.doctor.homepage.mapper.Rab1;
import com.mbmed.doctor.homepage.mapper.Rac1;
import com.mbmed.doctor.homepage.mapper.Rad1;
import com.mbmed.doctor.homepage.mapper.Vaj2;
import com.mbmed.doctor.homepage.mapper.Vam1;
import com.mbmed.doctor.homepage.mapper.Vao2;
import com.mbmed.doctor.login.bo.Bck1Bo;
import com.mbmed.doctor.login.bo.Vae1Bo;
import com.mbmed.doctor.login.mapper.Vae1;

/**
 * @file  Vae1Service.java
 * @author 刘武
 * @version 0.1
 * @todo	Vae1服务操作接口
 * Copyright(C), 2013-2014
 *		 Shenzhen Coordinates Software Development Co., Ltd.
 * History
 *   	1. Date: 2014-10-08 12:11:26
 *      	Author: 刘武
 *      	Modification: this file was created
 *   	2. ...
 */
@Path("/vae1")
@Component
public class Vae1Service {
	
	private static Logger logger = Logger.getLogger(Vae1.class);
	
	@Autowired
	private Vae1Bo vae1Bo;
	
	@Autowired
	private Vao2Bo vao2Bo;
	
	@Autowired
	private Bck1Bo bck1Bo;
	
	
	@Autowired
	private Vam1Bo vam1Bo;
	
	@Autowired
	private Rab1Bo rab1Bo;
	
	@Autowired
	private Vaj2Bo vaj2Bo;
	
	@Autowired
	private Rac1Bo rac1Bo;
	
	@Autowired
	private Rad1Bo rad1Bo;
	
	@Context
	Request request;

	
	/**
	 * 查找所有数据库记录
     * @return type : List 返回查询操作所有符合条件的记录的VO对象集合，操作失败返回null
     */
	@GET
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public List<Vae1> getAll() throws Exception{
        List<Vae1> list = new ArrayList<Vae1>();
        return vae1Bo.getAll();        
    }
	
    /**
     * 查找符合条件的所有数据库记录
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("{id}")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
    public Vae1 getVae1(@PathParam("id") String id) throws Exception{
    	Vae1 vae1 = null;
    	return vae1Bo.get(id);        
    }
		
	/**
     * 查询病人详情
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getvae1byvae01")
	@Produces({MediaType.APPLICATION_JSON})
    public Vae1 getVae1ByVaa04(@QueryParam("vae01") java.lang.String vae01) throws Exception{
    	Vae1 vae1 = null;
//    	return vae1Bo.get(id); 
    	vae1 = vae1Bo.getBaseVae1ByVae01(vae01);
    	return vae1;
    }
   
	
	
	/**
     * 查询病人详情
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getmedrecvae1byvae01")
	@Produces({MediaType.APPLICATION_JSON})
    public ModelVo getMedRecVae1ByVae01(@QueryParam("vae01") java.lang.String vae01) throws Exception{
		ModelVo modelVo = new ModelVo();
		Map<String,Object> map = new HashMap<String,Object>(); 
		
    	Vae1 vae1 = null;
    	vae1 = vae1Bo.getMedRecVae1ByVae01(vae01);
    	map.put("vae1", vae1);
    	
    	/*************/
    	
    	Vae1 diagnosisvae1 = null;
    	diagnosisvae1 = vae1Bo.getDiagnosisVae1ByVae01(vae01);
    	if(diagnosisvae1==null){
    		diagnosisvae1 = new Vae1();
    	}
    	
    	List<Vao2> vao2XyList = new ArrayList<Vao2>(); 
    	List<Vao2> vao2ZyList = new ArrayList<Vao2>(); 
    	
    	Map<String,String> vae1Map = new HashMap<String,String>();
    	vae1Map.put("vae01", vae01);
    	vae1Map.put("vao10", "0");
    	vao2XyList = vao2Bo.getVao2ByVae01(vae1Map);
    	if(vao2XyList==null || vao2XyList.size()==0){
    		vao2XyList = new ArrayList<Vao2>();
    	}
    	
    	vae1Map.put("vao10", "1");
    	vao2ZyList = vao2Bo.getVao2ByVae01(vae1Map);
    	if(vao2ZyList==null || vao2ZyList.size()==0){
    		vao2ZyList = new ArrayList<Vao2>();
    	}
    	
    	diagnosisvae1.setVao2XyList(vao2XyList);
    	diagnosisvae1.setVao2ZyList(vao2ZyList);
    	map.put("diagnosisvae1",diagnosisvae1);
    	
    	/************/
    	Vam1 vam1 = null;
		vam1 = vam1Bo.getMedrecVam1ByVae01(vae01);
		
		if(null == vam1){
			vam1 = new Vam1();
		}
			List<Rab1> rab1List = new ArrayList<Rab1>();
			rab1List = rab1Bo.getRab1ByVae01(vae01);
			if(!(null==rab1List)){
				vam1.setRab1List(rab1List);
			}
			
			List<Vaj2> vaj2List = new ArrayList<Vaj2>();
			vaj2List = vaj2Bo.getVaj2ByVae01(vae01);
			if(!(null==vaj2List)){
				vam1.setVaj2List(vaj2List);
			}
	    	
			map.put("vam1", vam1);
		/*************/
		Rac1 rac1 = null;
		rac1 = rac1Bo.getMedRecRac1ByVae01(vae01);
		
		if(null == rac1){
			rac1 = new Rac1();
		}
		
		List<Rad1> rad1List = new ArrayList<Rad1>();
		rad1List = rad1Bo.getRad1ByVae01(vae01);
		if(!(null==rad1List)){
				rac1.setRad1List(rad1List);
		}
		map.put("rac1", rac1);
		
		
		modelVo.setMap(map);
		
    	return modelVo;
	}
	/**
     * 根据ID查找符合条件的所有数据库记录
     * @param employeeId 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@SuppressWarnings("unchecked,rawtypes")
	@GET
	@Path("/getVae1List")
	@Produces({MediaType.APPLICATION_JSON})
    public List<Vae1> getVae1List(@QueryParam("bck01ListStr") java.lang.String bck01ListStr) throws Exception{
		//查询业务范围
//		String[] bck01Str = bck01ListStr.split(";");
		
		bck01ListStr = bck01ListStr.replaceAll(";", ",");
//		List<Vae1> list = new ArrayList<Vae1>();
//		for(int i=0; i< bck01Str.length ;i++){
//			int bck01 = Integer.parseInt(bck01Str[i]);
//			List<Vae1> vae1List = vae1Bo.getByBck01b(bck01);
//			list.addAll(vae1List);
//		}
//		
		Map map = new HashMap<>();
		map.put("bck01ls", bck01ListStr);
		List<Vae1> list = vae1Bo.getByBck01b(map);
//		System.out.println(bck01ListStr);
//		System.out.println(list.size());
    	return list;        
    }
	/**
     * 查询病人详情
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@SuppressWarnings("unchecked")
	@GET
	@Path("/getdiagnosisvae1byvae01")
	@Produces({MediaType.APPLICATION_JSON})
    public Vae1 getDiagnosisVae1ByVae01(@QueryParam("vae01") java.lang.String vae01) throws Exception{
    	Vae1 vae1 = null;
    	vae1 = vae1Bo.getDiagnosisVae1ByVae01(vae01);
    	
    	List<Vao2> vao2XyList = new ArrayList<Vao2>(); 
    	List<Vao2> vao2ZyList = new ArrayList<Vao2>(); 
    	
    	Map<String,String> vae1Map = new HashMap<String,String>();
    	vae1Map.put("vae01", vae01);
    	vae1Map.put("vao10", "0");
    	vao2XyList = vao2Bo.getVao2ByVae01(vae1Map);
    	
    	vae1Map.put("vao10", "1");
    	vao2ZyList = vao2Bo.getVao2ByVae01(vae1Map);
    	
    	vae1.setVao2XyList(vao2XyList);
    	vae1.setVao2ZyList(vao2ZyList);
    	
    	return vae1;
    }
	
	/**
	 * 查询婴儿信息
	 * @param vaa04
	 * @param vae01
	 * @return
	 * @throws Exception
	 */
	@GET
	@Path("/getVap1ByVaa04")
	@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
	public com.mbmed.doctor.commons.utils.ModelVo getVap1ByVaa04(@QueryParam("vaa04") java.lang.String vaa04,
			@QueryParam("vae01") java.lang.Integer vae01) throws Exception{
		return vae1Bo.getVap1ByVaa04(vaa04,vae01);
	}
	
	
	/**
     * 删除数据库中与传入的值对象对应的记录
     * @param vo 与数据库中记录对应的值对象
     * @return type : boolean 返回删除操作是否成功
     * @throws Exception
     */
	@DELETE
	@Path("{id}")
	public boolean removeVae1(@PathParam("id") String id) throws Exception{
		if(id == null) return false;
    	return vae1Bo.remove(id);

	}
	
}
